<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>备件列表</title>
		<!-- css代码 start -->
		<link href="../../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../../css/global.css" rel="stylesheet" />
		<link href="../../../../css/style.css" rel="stylesheet" />
		<link href="../../../../css/task.css" rel="stylesheet" />
		<style>
			#div {
			    width: 0px;
			    height: 0px;
			    background: red;
			    position: fixed;
			    top: 70%;
			    left: 50%;
		   }
		
		   /*移除底部或顶部三角,需要在删除此代码*/
		   .mui-popover .mui-popover-arrow:after {
				width: 0px;
		   }
		   .item_box .item .text{
			   height: auto;
			   line-height: 24px;
			   overflow: hidden;
		   }
		</style>
		<!-- css代码 end -->
	</head>

	<body>
		  <div id="div"></div>
		  <div id="popover" class="mui-popover shadow popover">
		   <p class="title" id="title">您确定要删除该备件信息吗？</p >
		   <div class="btn_box">
		    <span class="fl" onclick="closePopover()">取消</span>
			<span class="fr red" onclick="fixedDel()">确定</span>
		   </div>
		  </div>
		
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">备件列表</h1>
		</header>
		<div class="mui-content">
			<div class="details_con">
				<div class="item_box" id="itemBox">
					<!-- <div class="item">
						<p class="bar"><span class="number">1170001<img src="../../../../images/icon_3.png" /></span><span class="del">删除</span></p>
						<div class="text">2132345465768<span>备件名称：</span></div>
						<div class="text">备件1<span>备件序列号：</span></div>
						<div class="text">备件1<span>备件类型：</span></div>
						<div class="text">2345123456<span>备件数量：</span></div>
						<div class="text">2345123456<span>备件收货地：</span></div>
						<div class="text">2345123456<span>借货单号：</span></div>
					</div> -->
				</div>
			</div>
			<div class="btn_box">
				<span id="addParts" class="fl red one">添加备件</span>
			</div>
			<div style="height: 50px;"></div>
		</div>
		<!-- html代码 end -->
		
		<!-- js代码 start -->
		
		<!-- 基础js start -->
		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/utils/h.js"></script>
		<script src="../../../../js/constant.js"></script>
		<script src="../../../../js/common.js"></script>
		<script src="../../../../js/utils/base64.js"></script>
		<script src="../../../../js/utils/md5.js"></script>
		<script src="../../../../js/utils/sortMap.js"></script>
		<script src="../../../../js/utils/http.js"></script>
		<script src="../../../../js/app.js"></script>
		<!-- 基础js end -->
		
		<script type="text/javascript" charset="utf-8">
			
			// 提交状态 0未提交 1已提交
			var submitStatus = 0;
			var serviceNo, helpId 
			var needDelPartId; // 需要删除的备件信息id
			var needDelPid; // 需要删除的备件Pid
			var portType;
			var portList;
			
			function getNewStr(str) {
				if (JS.IsNullOrEmpty(str)) {
					return '';
				}
				return str;
			}
			
			function noData() {
				html = '<div class="nodata">—— 暂无数据 ——</div>';
				h("#itemBox").html(html);
			}
			
			function initData() {
				app.showWaiting()
				ajaxGet(BASE_URL + "cc/report/port/selectReportPorts", {
					"serviceNo": serviceNo,
					"helpId": helpId,
					"type": portType
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						if (data.data && data.data.length > 0) {
							var str = '';
							for(var c = 0;c<data.data.length;c++){
								 // str += '<div class="item">';
								 // str += '<div class="type">';
								 // str += '<p>备件编码：<span>'+getNewStr(data.data[c].partNumber)+'</span></p> ';
								 // str += '<p>备件类型：<span>'+getNewStr(data.data[c].portType)+'</span></p>';
								 // str += '<p>备件数量：<span>'+getNewStr(data.data[c].qtyCount)+'</span></p>';
								 // str += '<p>备件名称：<span>'+getNewStr(data.data[c].partName)+'</span></p>';
								 // str += '<p>备件序列号：<span>'+getNewStr(data.data[c].partSerialNumber)+'</span></p>';
								 // str += '<p>备件收货地址：<span>'+getNewStr(data.data[c].address)+'</span></p>';
								 // str += '<p>借货单号：<span>'+getNewStr(data.data[c].loanNumber)+'</span></p>';
								 // if(self.submitStatus == '0'){
									//  str += '<span  class="del" onclick="delPart('+data.data[c].id+')" style="float:right">删除</span>';
								 // }
								 // str += '</div></div>';
								 
								str += '<div class="item">'
								if (submitStatus != '1') {
									str += '	<p class="bar"><span class="del" onclick="delPart('+data.data[c].id+ ','+data.data[c].pid +')">删除</span></p>'
								}
								
								str += '	<div class="text"><span>备件编码：</span>'+getNewStr(data.data[c].partNumber)+'</div>'
								str += '	<div class="text"><span>备件名称：</span><span style="width: auto;float: none;padding-left: 80px;color:#333">'+getNewStr(data.data[c].partName)+'</span></div>'
								str += '	<div class="text"><span>序列号：</span>'+getNewStr(data.data[c].partSerialNumber)+'</div>'
								str += '	<div class="text"><span>备件类型：</span>'+getNewStr(getPortName(data.data[c].partType))+'</div>'
								str += '	<div class="text"><span>备件数量：</span>'+getNewStr(data.data[c].qtyCount)+'</div>'
								str += '	<div class="text"><span>收货地址：</span><span style="width: auto;float: none;padding-left: 80px;color:#333">'+getNewStr(data.data[c].address)+'</span></div>'
								str += '	<div class="text"><span>借货单号：</span>'+getNewStr(data.data[c].loanNumber)+'</div>'
								str += '</div>'
							}
							h('#itemBox').html(str);
							if (submitStatus == '1') {
								h('.del').parent().hide()
							}
						} else {
							noData()
						}
					} else {
						noData()
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					noData()
					app.toast(errorMsg)
				});
			}
			
			function fixedDel() {
				mui("#popover").popover('toggle', document.getElementById("div"));
				app.showWaiting('删除中...')
				ajaxGet(BASE_URL + 'cc/report/port/removeReportPort', {
					enginnerId: app.getUser().enginnerId,
					reportPortId: needDelPartId,
					pid: needDelPid
				}, function(data) {
					app.closeWaiting()
					if (data.code === 200) {
						app.toast('删除成功')
						initData()
					} else {
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					app.closeWaiting()
					app.toast(errorMsg)
				})
			}
			
			function closePopover() {
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
			
			function delPart(id,pid) {
				needDelPartId = id;
				needDelPid = pid;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
			
			function getPortName(val) {
				if (val == "1") {
					return "更换";
				} else if (val == "2") {
					return "漏发";
				} else if (val == "3") {
					return "错发";
				} else if (val == "4") {
					return "多发";
				} else if (val == "5") {
					return "个人工具";
				} else if (val == "6") {
					return "漏订";
				} else if (val == "7") {
					return "错订";
				} else if (val == "8") {
					return "故障";
				} else if (val == "9") {
					return "破损";
				}
				// for (i= 0; i<portList.length; i++){
				// 	if (val == portList[i].value){
				// 		return portList[i].text
				// 	}
				// }
			}
			
			(function($, doc) {
				$.init();
		
				$.plusReady(function() {
					var self = plus.webview.currentWebview();
					console.log(self.syncFlag)
					serviceNo = self.serviceNo
					helpId = self.helpId
					submitStatus = self.submitStatus
					portType = self.portType
					console.log("submitStatus" + submitStatus)
					// ajaxGetJson(BASE_URL + 'cc/dict/selectDict', {
					// 	dictType: 'parttype_report'
					// }, function(data){
					// 	portList = data;				
					// });
					initData()
					
					if(submitStatus=='1'){
						h('#addParts').parent().hide()
					}
					
					//添加备件
					h('#addParts').tap(function() {
						app.hideSoftKeybord()
						app.jumpTo('/view/service/report/errorhot/sparePartsAdd.html',
							'view/service/report/errorhot/sparePartsAdd.html', {
								serviceNo:serviceNo,
								helpId:helpId,
								portType: portType
							})
					})
					
				});
			}(mui, document));
		</script>
		<!-- js代码 end -->
	</body>

</html>
